home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 124 / cd-rom 124.iso / edu / tuxmath / tuxmathscrabble / asymptopia / myutil.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2003-11-16  |  3.4 KB  |  86 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.2)
  3.  
  4. '''
  5. /***************************************************************************
  6.  
  7. \tAuthor \t\t\t:Charles B. Cosse 
  8. \t
  9. \tEmail\t\t\t:ccosse@asymptopia.com
  10. \t\t\t\t\t
  11. \t\t\t\t\t
  12. \tCopyright\t\t:(C) 2002,2003 Asymptopia Software.
  13. \t
  14.  ***************************************************************************/
  15. /***************************************************************************
  16.                          myutil.py
  17.  
  18.  ***************************************************************************/
  19.  
  20. /***************************************************************************
  21.  *                                                                         *
  22.  *   This program is free software; you can redistribute it and/or modify  *
  23.  *   it under the terms of the GNU General Public License as published by  *
  24.  *   the Free Software Foundation; either version 2 of the License, or     *
  25.  *   (at your option) any later version. (Please note that if you use this *
  26.  *   code you must give credit by including the Author and Copyright       *
  27.  *   info at the top of this file).                                        *
  28.  ***************************************************************************/
  29. '''
  30. import pygame
  31. import os
  32. import sys
  33. from pygame.locals import *
  34.  
  35. try:
  36.     for sitepkgdir in sys.path:
  37.         if sitepkgdir[-13:] == 'site-packages':
  38.             break
  39.         
  40. except:
  41.     pass
  42.  
  43.  
  44. def load_image(name, colorkey = None):
  45.     fullname = os.path.join(sitepkgdir, name)
  46.     
  47.     try:
  48.         image = pygame.image.load(fullname)
  49.     except pygame.error:
  50.         message = None
  51.         print 'Cannot load image:', name
  52.         raise SystemExit, message
  53.  
  54.     image = image.convert()
  55.     if colorkey is not None:
  56.         if colorkey is -1:
  57.             colorkey = image.get_at((0, 0))
  58.         
  59.         image.set_colorkey(colorkey, RLEACCEL)
  60.     
  61.     return (image, image.get_rect())
  62.  
  63.  
  64. def load_sound(name):
  65.     
  66.     class NoneSound:
  67.         
  68.         def play(self):
  69.             pass
  70.  
  71.  
  72.     if not (pygame.mixer) or not pygame.mixer.get_init():
  73.         return NoneSound()
  74.     
  75.     fullname = os.path.join(sitepkgdir, name)
  76.     
  77.     try:
  78.         sound = pygame.mixer.Sound(fullname)
  79.     except pygame.error:
  80.         message = None
  81.         print 'Cannot load sound:', fullname
  82.         raise SystemExit, message
  83.  
  84.     return sound
  85.  
  86.